
import os

def read_files(dir_path):
    for file in os.listdir(dir_path):
        with open(os.path.join(dir_path, file), 'r') as f:
            for line in f:
                yield line.strip()

import redis

def write_redis(redis_client, data_list):
    pipe = redis_client.pipeline()
    for data in data_list:
        device, model_num, score = data.split(',')
        score = int(float(score)*10000)
        pipe.hset(device, model_num, score)
        if len(pipe) == 1000:
            pipe.execute()
            pipe = redis_client.pipeline()
    pipe.execute()

if __name__ == '__main__':
    redis_client = redis.Redis(host='localhost', port=6379, db=0)
    # write_redis(redis_client, (read_files('data')))
    write_redis(redis_client, read_files('data'))